package com.lxmes.procontrol.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.procontrol.domain.NcProProcessControl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.procontrol.domain.NcProOrderInfo;
import com.lxmes.procontrol.service.INcProOrderInfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 工单明细Controller
 * 
 * @author 张志煜
 * @date 2022-12-29
 */
@RestController
@RequestMapping("/procontrol/orderInfo")
public class NcProOrderInfoController extends BaseController
{
    @Autowired
    private INcProOrderInfoService ncProOrderInfoService;

    /**
     * 查询工单明细列表
     */
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcProOrderInfo ncProOrderInfo)
    {
        startPage();
        List<NcProOrderInfo> list = ncProOrderInfoService.selectNcProOrderInfoList(ncProOrderInfo);
        return getDataTable(list);
    }

    /**
     * 导出工单明细列表
     */
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:export')")
    @Log(title = "工单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcProOrderInfo ncProOrderInfo)
    {
        List<NcProOrderInfo> list = ncProOrderInfoService.selectNcProOrderInfoList(ncProOrderInfo);
        ExcelUtil<NcProOrderInfo> util = new ExcelUtil<NcProOrderInfo>(NcProOrderInfo.class);
        util.exportExcel(response, list, "工单明细数据");
    }

    /**
     * 获取工单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncProOrderInfoService.selectNcProOrderInfoById(id));
    }
    @GetMapping(value = "/getBgOrderInfo/{id}")
    public AjaxResult getBgOrderInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncProOrderInfoService.getBgOrderInfo(id));
    }

     @GetMapping(value = "/getBgOrderinfoItem/{id}")
    public AjaxResult getBgOrderinfoItem(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncProOrderInfoService.getBgOrderinfoItem(id));
    }

    /**
     * 新增工单明细
     */
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:add')")
    @Log(title = "工单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcProOrderInfo ncProOrderInfo)
    {
        return toAjax(ncProOrderInfoService.insertNcProOrderInfo(ncProOrderInfo));
    }
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:bg')")
    @Log(title = "工单明细报工", businessType = BusinessType.INSERT)
    @PostMapping("/addBgOrderInfo")
    public AjaxResult addBgOrderInfo(@RequestBody NcProOrderInfo ncProOrderInfo)
    {
        return toAjax(ncProOrderInfoService.addBgOrderInfo(ncProOrderInfo));
    }

    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:jd')")
    @Log(title = "工单明细接单", businessType = BusinessType.UPDATE)
    @PutMapping("/addJdOrderInfo")
    public AjaxResult addJdOrderInfo(@RequestBody NcProOrderInfo ncProOrderInfo)
    {
        return toAjax(ncProOrderInfoService.updateNcProOrderInfo(ncProOrderInfo));
    }
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:jd')")
    @GetMapping(value = "/addJdAllOrderInfo/{ids}")
    public AjaxResult addJdAllOrderInfo(@PathVariable Long[] ids)
    {
        return toAjax(ncProOrderInfoService.addJdAllOrderInfo(ids));
    }

    /**
     * 修改工单明细
     */
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:edit')")
    @Log(title = "工单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcProOrderInfo ncProOrderInfo)
    {
        return toAjax(ncProOrderInfoService.updateNcProOrderInfo(ncProOrderInfo));
    }

    /**
     * 删除工单明细
     */
    @PreAuthorize("@ss.hasPermi('procontrol:orderInfo:remove')")
    @Log(title = "工单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncProOrderInfoService.deleteNcProOrderInfoByIds(ids));
    }
}
